package com.shaozi.nc.utils;

import java.util.ArrayList;
import java.util.List;

import com.shaozi.data.mq.business.bean.MqTargetUserBean;
import com.shaozi.nc.bean.briefreport.BriefReportMsgBean;
import com.shaozi.nc.data.model.BriefReportModel;
import com.shaozi.nc.data.model.SecretaryModel;

public class BriefReportHelper {
	public static BriefReportMsgBean toMsgBean(BriefReportModel briefReport, String userId) {
		if ((briefReport.getUsers() == null) || (briefReport.getUsers().isEmpty()))
			return null;
		for (MqTargetUserBean user : briefReport.getUsers()) {
			if (user.getUserId() != null && user.getUserId().equals(userId)) {
				BriefReportMsgBean msgBean = new BriefReportMsgBean();
				initSecretaryMsgBean(msgBean, briefReport, user);
				return msgBean;
			}
		}
		return null;
	}

	public static List<BriefReportMsgBean> toMsgBean(BriefReportModel briefReport) {
		if ((briefReport.getUsers() == null) || (briefReport.getUsers().isEmpty()))
			return null;
		List<BriefReportMsgBean> ret = new ArrayList<>();
		for (MqTargetUserBean user : briefReport.getUsers()) {
			BriefReportMsgBean msgBean = new BriefReportMsgBean();
			initSecretaryMsgBean(msgBean, briefReport, user);
			ret.add(msgBean);
		}
		return ret;
	}

	public static List<BriefReportMsgBean> toMsgBean(SecretaryModel model) {
		if ((model.getUsers() == null) || (model.getUsers().isEmpty()))
			return null;
		List<BriefReportMsgBean> ret = new ArrayList<>();
		for (MqTargetUserBean user : model.getUsers()) {
			BriefReportMsgBean msgBean = new BriefReportMsgBean();
			initSecretaryMsgBean(msgBean, model, user);
			ret.add(msgBean);
		}
		return ret;
	}

	private static void initSecretaryMsgBean(BriefReportMsgBean msgBean, SecretaryModel briefReport,
			MqTargetUserBean user) {
		SecretaryHelper.commonInitSecretaryMsgBean(msgBean, briefReport, user);
		msgBean.setBriefreportId(briefReport.getId());
	}

	private static void initSecretaryMsgBean(BriefReportMsgBean msgBean, BriefReportModel briefReport,
			MqTargetUserBean user) {
		SecretaryHelper.commonInitSecretaryMsgBean(msgBean, briefReport, user);
		msgBean.setBriefreportId(briefReport.getId());
	}
}
